<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- base href="http://www.codeslinger.co.uk/pages/projects/gameboy/dma.html" --></head><body><div style="background:#fff;border:1px solid #999;margin:-1px -1px 0;padding:0;"><div style="background:#ddd;border:1px solid #999;color:#000;font:13px arial,sans-serif;font-weight:normal;margin:12px;padding:8px;text-align:left">Esta es la versión en caché de <a href="http://www.codeslinger.co.uk/pages/projects/gameboy/dma.html" style="text-decoration: underline; color: rgb(0, 0, 204);">http://www.codeslinger.co.uk/pages/projects/gameboy/dma.html</a>
 de Google. Se trata de una captura de pantalla de la página tal como 
esta se mostraba el 30 Abr 2011 11:36:05 GMT. Es posible que la <a href="http://www.codeslinger.co.uk/pages/projects/gameboy/dma.html" style="text-decoration: underline; color: rgb(0, 0, 204);">página</a> haya sufrido modificaciones durante este tiempo. <a href="http://www.google.com/intl/es/help/features_list.html#cached" style="text-decoration: underline; color: rgb(0, 0, 204);">Más información</a><br><br><div style="float:right"><a href="http://webcache.googleusercontent.com/search?q=cache:ufH-q2ffEUAJ:www.codeslinger.co.uk/pages/projects/gameboy/dma.html+codeslinger+gameboy+dma+transfer&amp;hl=es&amp;gl=ar&amp;strip=1" style="text-decoration: underline; color: rgb(0, 0, 204);">Versión de solo texto</a></div>
<div>Se han resaltado estos términos de búsqueda: <span style="background:#ffff66;color:black;font-weight:bold">codeslinger</span>&nbsp;<span style="background:#a0ffff;color:black;font-weight:bold">gameboy</span>&nbsp;<span style="background:#99ff99;color:black;font-weight:bold">dma</span>&nbsp;<span style="background:#ff9999;color:black;font-weight:bold">transfer</span>&nbsp;&nbsp;</div></div></div><div style="position:relative">



<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="description" content="_Emulation Programming_">
<meta name="keywords" content="_Emulation,Chip8,Gameboy,NES,SNES,Genesis,Master,System,Mega,Drive_">
<meta name="author" content="CodeSlinger /">
<link rel="stylesheet" type="text/css" href="8%20DMA%20Transfer_files/css.css" media="screen,projection" title="CodeSlinger (screen)">
<link rel="stylesheet" type="text/css" href="8%20DMA%20Transfer_files/print.css" media="print">
<title>codeslinger.co.uk</title>



<div>
<br><br>
</div>

<div id="container">
<div id="logo">
<h1><a href="http://www.codeslinger.co.uk/index.html"><b style="color:black;background-color:#ffff66">codeslinger</b>.co.uk</a></h1>
</div>

<div id="navitabs">
<h2 class="hide">Site menu:</h2>
<a class="navitab" href="http://www.codeslinger.co.uk/index.php">Home</a><span class="hide"> | </span>
<a class="navitab" href="http://www.codeslinger.co.uk/pages/basics.html">Basics</a><span class="hide"> | </span>
<a class="navitab" href="http://www.codeslinger.co.uk/pages/projects/zuko.html">Zuko</a><span class="hide"> | </span>
<a class="navitab" href="http://www.codeslinger.co.uk/pages/projects/megadrive.html">Mega Drive/Genesis</a><span class="hide"> | </span>
<a class="navitab" href="http://www.codeslinger.co.uk/pages/projects/mastersystem.html">Master System</a><span class="hide"> | </span>
<a class="activenavitab" href="http://www.codeslinger.co.uk/pages/projects/gameboy.html"><b style="color:black;background-color:#a0ffff">Gameboy</b></a><span class="hide"> | </span>
<a class="navitab" href="http://www.codeslinger.co.uk/pages/projects/chip8.html">Chip8</a><span class="hide"> | </span>
<a class="navitab" href="http://www.codeslinger.co.uk/pages/blog/index.html">Blog</a><span class="hide"> | </span>
</div>
	
<div id="desc">
<h2><b style="color:black;background-color:#ffff66">codeslinger</b>.co.uk</h2>
<p> <b style="color:black;background-color:#a0ffff">Gameboy</b> - <b style="color:black;background-color:#99ff99">DMA</b></p>

</div>

<div id="main">

<h3><b>Direct Memory Access:</b></h3>
<p>

As explained in the <a href="http://www.codeslinger.co.uk/pages/projects/gameboy/lcd.html">LCD</a> chapter the CPU can only access the Sprite Attributes table during the duration of one of the LCD modes (mode 2).
The Direct Memory Access (<b style="color:black;background-color:#99ff99">DMA</b>) is a way of copying data to the sprite RAM at the appropriate time removing all responsibility from the main program.<br><br>

The game launches a <b style="color:black;background-color:#99ff99">DMA</b>
 when it attempts to write to memory address 0xFF46 so we need to add 
the following to WriteMemory to trap writing to this address:

</p><p class="code">
else if (address == 0xFF46)<br>
{<br>
&nbsp;&nbsp; DoDMATransfer(data) ;<br>
}
</p>
 

<p></p>

<h3><b>Implementation of the <b style="color:black;background-color:#99ff99">DMA</b> <b style="color:black;background-color:#ff9999">Transfer</b>:</b> </h3>
<p>
The code behind the <b style="color:black;background-color:#99ff99">DMA</b> <b style="color:black;background-color:#ff9999">transfer</b> is really very simple but to understand what is needed can be a little tricky.

As mentioned earlier the destination address of the <b style="color:black;background-color:#99ff99">DMA</b> is the sprite RAM between memory adddress (0xFE00-0xFE9F)
which means that a total of 0xA0 bytes will be copied to this region. The source address is represented by the
data being written to address 0xFF46 except this value is the source address divided by 100. So to get the correct
start address it is the data being written to * 100 (to make it faster instead of multiplying by 100 we will shift left
8 places, it is the same thing). Now we have all the information to write the DoDMATransfer function like so:

</p><p class="code">
void Emulator::DoDMATransfer(BYTE data)<br>
{<br>
&nbsp;&nbsp; WORD address = data &lt;&lt; 8 ; // source address is data * 100<br>
&nbsp;&nbsp; for (int i = 0 ; i &lt; 0xA0; i++)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp; WriteMemory(0xFE00+i, ReadMemory(address+i)) ;<br>
&nbsp;&nbsp; }<br>
}
</p>

Thats all there is to <b style="color:black;background-color:#99ff99">DMA</b>. The next chapter is on <a href"graphics.html"="">Graphics Emulation</a>. You may want to grab
a sandwich and a coke before you start that one.

<br><br>
<p></p>



</div>

<div id="sidebar">
<h3><b style="color:black;background-color:#a0ffff">Gameboy</b> Emulation:</h3>

<p>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/beginning.html">Getting Started</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/hardware.html">The Hardware</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/memory.html">Memory Control and Map</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/banking.html">ROM and RAM Banking</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/timers.html">The Timers</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/interupts.html">Interupts</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/lcd.html">LCD</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/dma.html"><b style="color:black;background-color:#99ff99">DMA</b> <b style="color:black;background-color:#ff9999">Transfer</b></a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/graphics.html">Graphic Emulation</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/joypad.html">Joypad Emulation</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/opcodes.html">Opcode Examples</a><span class="hide"> | </span>
<a class="sidelink" href="http://www.codeslinger.co.uk/pages/projects/gameboy/finished.html">Finished Product</a><span class="hide"> | </span>

</p>

</div>
    
<div id="footer">
Copyright © 2008 <b style="color:black;background-color:#ffff66">codeslinger</b>.co.uk
</div>

</div>




</div></body></html>